﻿Imports System.Web.Security
Imports System.Web.UI
Imports System.Data.OleDb
Imports System.Data.Entity.Validation

Public Class sms_moneytype
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
    Protected Sub GridView1_RowEditing(sender As Object, e As GridViewEditEventArgs)
        Dim id As Integer
        id = Convert.ToInt32(GridView1.DataKeys(e.NewEditIndex).Value)

        hdn_id.Value = id

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString001").ConnectionString)
        Dim SqlString As String = "select * from sms_moneytype  where ID =  @ID"

        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)


        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@ID", id)

        oleDbConn.Open()

        Dim sda As OleDbDataAdapter = New OleDbDataAdapter(cmd)
        Dim ds As DataSet = New DataSet()
        sda.Fill(ds)


        Dim dr As DataRow = ds.Tables(0).Rows(0)

        txt_sms_type.Text = dr("moneytype").ToString()

        Disable()
        Button1.Text = "Edit"



    End Sub
    Private Sub Disable()
        txt_sms_type.Enabled = False

    End Sub

    Private Sub Enable()
        txt_sms_type.Enabled = True
    End Sub
    Protected Sub Button1_Click(sender As Object, e As EventArgs)
        Try
            If Button1.Text = "Edit" Then
                Enable()
                Button1.Text = "Save"
            ElseIf Button1.Text = "Save" Then

                If (txt_sms_type.Text <> "") Then

                    Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString001").ConnectionString)
                    Dim SqlString As String = "update sms_moneytype set moneytype=@moneytype where  ID =  @ID"

                    Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)


                    cmd.CommandType = CommandType.Text
                    cmd.Parameters.AddWithValue("@moneytype", txt_sms_type.Text)
                    cmd.Parameters.AddWithValue("@ID", hdn_id.Value)

                    oleDbConn.Open()
                    cmd.ExecuteNonQuery()
                    Button1.Text = "Edit"
                    txt_sms_type.Text = ""
                    GridView1.EditIndex = -1
                    GridView1.DataSourceID = "SqlDataSource5"
                    GridView1.DataBind()
                    'Disable()
                    
                End If

            End If

        Catch ex As DbEntityValidationException

        End Try


    End Sub
    Protected Sub btncancel_Click(sender As Object, e As EventArgs)
        Button1.Text = "Edit"
        Disable()


    End Sub

    Protected Sub GridView1_RowDeleting(sender As Object, e As GridViewDeleteEventArgs)
        Dim id As Integer
        id = Convert.ToInt32(GridView1.DataKeys(e.RowIndex).Value)

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString001").ConnectionString)
        Dim SqlString As String = "Delete from sms_moneytype where ID =  @ID"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)


        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@ID", id)

        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        'GridView1.DataSourceID = "SqlDataSource5"
        'GridView1.DataBind()
        txt_sms_type.Text = ""
        Response.Redirect("~/Account/sms_moneytype.aspx")

    End Sub

End Class